package com.jisuan.contract.controller;

import com.jisuan.contract.common.utils.PageResult;
import com.jisuan.contract.common.utils.Result;
import com.jisuan.contract.entity.EmployeeEntity;
import com.jisuan.contract.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 员工表
 *
 * @author 王大军
 * @email wangdajunzy@163.com
 * @date 2022-01-07 12:05:38
 */
@RestController
@RequestMapping("contract/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 列表
     */
    @GetMapping
    public Result<PageResult> list(@RequestParam Map<String, Object> params,
                                   EmployeeEntity employee)
    {
        PageResult pageResult = employeeService.queryPage(params, employee);
        return Result.success(pageResult);
    }

    /**
     * 信息
     */
    @GetMapping("/{id}")
    public Result<EmployeeEntity> info(@PathVariable("id") Long id)
    {
		EmployeeEntity employee = employeeService.getById(id);
        return Result.success(employee);
    }

    /**
     * 保存
     */
    @PostMapping
    public Result<?> save(@RequestBody EmployeeEntity employee)
    {
		employeeService.save(employee);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping
    public Result<?> update(@RequestBody EmployeeEntity employee)
    {
		employeeService.updateById(employee);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping
    public Result<?> delete(@RequestBody Long[] ids)
    {
		employeeService.removeByIds(Arrays.asList(ids));
        return Result.success();
    }

}
